package com.example.planstudio;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MyDBhelper extends SQLiteOpenHelper {
    private SQLiteDatabase db;
    public MyDBhelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        db=this.getWritableDatabase();
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("create table noteInfo(id integer primary key autoincrement,time text,event text)");
        sqLiteDatabase.execSQL("create table role(name_id integer PRIMARY KEY,name  VARCHAR(100))");
        sqLiteDatabase.execSQL("create table words(id integer ,type integer,name_id integer,word  VARCHAR(500))");
        sqLiteDatabase.execSQL("create table money(breakfast float ,lunch_dinner float ,snack float ,amusement float )");
        sqLiteDatabase.execSQL("INSERT INTO role(name_id,name)VALUES (2131230952,'前辈')");
        sqLiteDatabase.execSQL("INSERT INTO role(name_id,name)VALUES (2131230827,'雪之下由乃');");
        sqLiteDatabase.execSQL("INSERT INTO role(name_id,name)VALUES (2131230953,'C罗');");
        sqLiteDatabase.execSQL("INSERT INTO role(name_id,name)VALUES (2131230954,'妖王');");
        sqLiteDatabase.execSQL("INSERT INTO role(name_id,name)VALUES (2131230955,'小呆呆');");
        sqLiteDatabase.execSQL("INSERT INTO role(name_id,name)VALUES (2131230956,'山田凉');");
        sqLiteDatabase.execSQL("INSERT INTO role(name_id,name)VALUES (2131230957,'雅思前考官Paul老师');");
        sqLiteDatabase.execSQL("INSERT INTO role(name_id,name)VALUES (2131230958,'亚古兽');");
        sqLiteDatabase.execSQL("INSERT INTO role(name_id,name)VALUES (2131230959,'一个普通的足球');");
        for(int i=1;i<=6;i++){
            for(int j=1;j<=9;j++){
                sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES ('"+j+"','"+i+"',2131230952,'你比较喜欢哪种玩法');");
            }
        }
        for(int i=1;i<=6;i++){
            for(int j=1;j<=9;j++){
                sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES ('"+j+"','"+i+"',2131230953,'siuuuuuuuuuuuuu');");
            }
        }
        for(int i=1;i<=6;i++){
            for(int j=1;j<=9;j++){
                sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES ('"+j+"','"+i+"',2131230954,'lover，lover');");
            }
        }
        for(int i=1;i<=6;i++){
            for(int j=1;j<=9;j++){
                sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES ('"+j+"','"+i+"',2131230955,'这个玩具枪我以前没有玩过哟');");
            }
        }

        for(int i=1;i<=6;i++){
            for(int j=1;j<=9;j++){
                sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES ('"+j+"','"+i+"',2131230956,'有钱真好，我会努力吃草过日子的');");
            }
        }
        for(int i=1;i<=6;i++){
            for(int j=1;j<=9;j++){
                sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES ('"+j+"','"+i+"',2131230957,'Now in this first part, I’d like to ask you some questions about yourself');");
            }
        }
        for(int i=1;i<=6;i++){
            for(int j=1;j<=9;j++){
                sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES ('"+j+"','"+i+"',2131230958,'亚古兽进化，暴龙兽');");
            }
        }
        for(int i=1;i<=6;i++){
            for(int j=1;j<=9;j++){
                sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES ('"+j+"','"+i+"',2131230959,'。。。。。。');");
            }
        }
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (1,1,2131230827,'只吃这点真的够吗，为了继续你那渣子般的生活，食物是必须的');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (2,1,2131230827,'早上摄入必要的糖分是必须的，这对某人的脑袋很有帮助');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (3,1,2131230827,'你的饮食还是那么没有品位呢，真的是');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (4,1,2131230827,'吃完了要不要来杯红茶呢');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (5,1,2131230827,'我对自己的烹饪手艺还是很自信的，要尝尝看吗');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (6,1,2131230827,'早餐多吃点');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (7,1,2131230827,'活着要进食，吃了也是浪费资源，真是个让人纠结的家伙');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (8,1,2131230827,'你怎么吃那么多，真是浪费资源呢');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (9,1,2131230827,'你是猪吗');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (1,2,2131230827,'原来你也是需要进食的呀，明明去光合作用不就好了嘛');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (2,2,2131230827,'吃饭时间虽然不是很长但是还是不要吃太快哦');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (3,2,2131230827,'我好饿');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (4,2,2131230827,'吃的很多容易胖的哟');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (5,2,2131230827,'今天雪之下雪乃该去吃什么好呢');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (6,2,2131230827,'吃饱了嘛');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (7,2,2131230827,'wow，是出去聚餐了吗');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (8,2,2131230827,'你是猪吗');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (9,2,2131230827,'活着要进食，吃了也是浪费资源，真是个让人纠结的家伙');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (1,3,2131230827,'你怎么又在吃独食');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (2,3,2131230827,'这么点，你已经落魄到这种地步了吗');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (3,3,2131230827,'你为什么不去吃草呀');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (4,3,2131230827,'是谁跟我保证过要认真吃正餐的吧');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (5,3,2131230827,'这样吃零食真的不会影响对于正餐的食欲吗');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (6,3,2131230827,'可以分享给我吗，这个味道真的好棒呀');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (7,3,2131230827,'这零食钱，都可以吃好几顿饭了');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (8,3,2131230827,'你这样吃会死得快的');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (9,3,2131230827,'你是要上天啊');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (1,4,2131230827,'希望今天你可以玩的尽兴');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (2,4,2131230827,'快说，跟谁出去的');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (3,4,2131230827,'这么点，你已经落魄到这种地步了吗');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (4,4,2131230827,'快说，跟谁出去的');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (5,4,2131230827,'下次能不能叫上我呀');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (6,4,2131230827,'呵，又不学习是吧');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (7,4,2131230827,'还有钱回来吗');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (8,4,2131230827,'跟谁？');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (9,4,2131230827,'别回来了');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (1,5,2131230827,'就你这浅薄的收入，你还是别活了');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (2,5,2131230827,'不愧是你，赚这么少还能生存呢');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (3,5,2131230827,'哇，你好棒呀');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (4,5,2131230827,'人类的能力是有极限的，越是工作，就越是会发现人的耐力是有限的…除非能成为我一样超越人类的存在');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (5,5,2131230827,'无论多少都是努力的证明，加油哟');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (6,5,2131230827,'世界上没有那么多事是一直尽人意的，你只要努力就好，总会得到你想要的');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (7,5,2131230827,'加qq3178064620，转我500，谢谢');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (8,5,2131230827,'给我500，我实现你一个愿望');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (9,5,2131230827,'钱都给我，快点，转我微信');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (1,6,2131230827,'我有时真想看看你的脑子都装着些啥');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (2,6,2131230827,'sb，我是一个记账软件，你发我这个是什么意思啊');");
        sqLiteDatabase.execSQL("INSERT INTO words(id,type,name_id,word)VALUES (3,6,2131230827,'打代码就够烦了，还碰上你这种笨蛋');");
    }

    public boolean insertData(String content){
        SimpleDateFormat sdf=new SimpleDateFormat("hh:mm");
        Date date=new Date(System.currentTimeMillis());
        String time=sdf.format(date);
//        String finalDate=sdf.format(date);
        ContentValues contentValues=new ContentValues();
        contentValues.put("event",content);
        contentValues.put("time",time);
        long i=db.insert("noteInfo",null,contentValues);
        return i>0?true:false;
    }

    public boolean insert_breakfast(double money){

        ContentValues contentValues=new ContentValues();
        contentValues.put("breakfast",money);
        contentValues.put("lunch_dinner",0);
        contentValues.put("snack",0);
        contentValues.put("amusement",0);
        long i=db.insert("money",null,contentValues);
        return i>0?true:false;
    }
    public boolean insert_lunch(double money){

        ContentValues contentValues=new ContentValues();
        contentValues.put("lunch_dinner",money);
        contentValues.put("snack",0);
        contentValues.put("amusement",0);
        contentValues.put("breakfast",0);
        long i=db.insert("money",null,contentValues);
        return i>0?true:false;
    }
    public boolean insert_snack(double money){

        ContentValues contentValues=new ContentValues();
        contentValues.put("snack",money);
        contentValues.put("lunch_dinner",0);
        contentValues.put("breakfast",0);
        contentValues.put("amusement",0);
        long i=db.insert("money",null,contentValues);
        return i>0?true:false;
    }
    public boolean insert_amusement(double money){

        ContentValues contentValues=new ContentValues();
        contentValues.put("amusement",money);
        contentValues.put("snack",0);
        contentValues.put("lunch_dinner",0);
        contentValues.put("breakfast",0);
        long i=db.insert("money",null,contentValues);
        return i>0?true:false;
    }
    public boolean insert_receive(double money){

        ContentValues contentValues=new ContentValues();
        contentValues.put("receive",money);
        long i=db.insert("money",null,contentValues);
        return i>0?true:false;
    }
    public boolean deleteData(String deleteId){
        int i=db.delete("noteInfo","id=?",new String[]{deleteId});
        return i>0?true:false;
    }

    public boolean updateData(String updateId,String updateContent){
        SimpleDateFormat sdf=new SimpleDateFormat("hh:mm");
        Date date=new Date(System.currentTimeMillis());
        String time=sdf.format(date);
        ContentValues contentValues=new ContentValues();
        contentValues.put("event",updateContent);
        contentValues.put("time",time);
        int i=db.update("noteInfo",contentValues,"id=?",new String[]{updateId});
        return i>0?true:false;
    }

    public List<Note> query(){
        List<Note> list=new ArrayList<>();
        Cursor cursor=db.query("noteInfo",null,null,null,null,null,null,null);
        while (cursor.moveToNext()){
            Note note=new Note();
            note.setId(String.valueOf(cursor.getInt(0)));
            note.setTime(cursor.getString(1));
            note.setEvent(cursor.getString(2));
            list.add(note);
        }
        return list;
    }

    public List<role> query2(){
        List<role> list=new ArrayList<>();
        Cursor cursor=db.query("role",null,null,null,null,null,null,null);
//int i=0;
        while (cursor.moveToNext()){
//            System.out.println("洒洒");

            role role1=new role();
            role1.setName_id(cursor.getInt(0));
            role1.setName(cursor.getString(1));

            list.add(role1);
        }
//        System.out.println(i);
        return list;
    }

    public String query3(int id,int type,int name_id){
        words words=null;
        String sql= "SELECT * FROM words where id='"+id+"'and type='"+type+"'and name_id='"+name_id+"'";
        Cursor cursor = db.rawQuery(sql,null);
        String word = null;
        while (cursor.moveToNext()){

            word=cursor.getString(3);
              return word;
        }
        return word;
    }
    public money query4(){
        money M=new money(0,0,0,0);
        Cursor cursor=db.query("money",null,null,null,null,null,null,null);
        while (cursor.moveToNext()){
            float temp_breakfast=cursor.getFloat(0);
            float temp_lunch=cursor.getFloat(1);
            float temp_sanck=cursor.getFloat(2);
            float temp_amusement=cursor.getFloat(3);
            M.setBreakfast(M.getBreakfast()+temp_breakfast);
            M.setLunch_dinner(M.getLunch_dinner()+temp_lunch);
            M.setSnack(M.getSnack()+temp_sanck);
            M.setAmusement(M.getAmusement()+temp_amusement);
        }
        return M;}
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}
